package classroom.edu.info.manager.service;

import classroom.edu.info.manager.dao.StudentDao;
import classroom.edu.info.manager.domain.Student;

public class StudentService {
    private StudentDao studentDao = new StudentDao();


    public boolean addStudent(Student stu) {

        return studentDao.addStudent(stu);
    }

    public boolean isExists(String id) {
        Student[] student = studentDao.selectStudent();
        boolean exists = false;
        for (int i = 0; i < student.length; i++) {
            Student stu = student[i];
            if (stu != null && id.equals(stu.getId())) {
                exists = true;
                break;
            }
        }
        return exists;
    }

    public Student[] selectStudent() {
        Student[] student = studentDao.selectStudent();
        for (int i = 0; i < student.length; i++) {
            if (student[i] != null) {
                return student;
            }
        }
        return null;
    }


    public void deleteStudent(String id) {
        studentDao.deleteStudent(id);
    }

    public boolean isNull() {
        Student[] student = studentDao.selectStudent();
        for (int i = 0; i < student.length; i++) {
            if (student[i]!=null){
                return true;
            }
        }
        return false;
    }


    public void updateStudent(Student newStudent) {
        studentDao.updateStudent(newStudent);
    }
}

